package entity

import (
	"fmt"
	"time"

	"gorm.io/gorm"
	"shqsoft.cn/pas3ui/base"
)

//ShXykfqzsdr 信用卡分期中收导入
type ShXykfqzsdr struct {
	ID    int       `gorm:"AUTO_INCREMENT;primary_key;column:ID"`
	KHMC  string    `gorm:"column:KHMC"` //客户姓名
	FKSJ  time.Time `gorm:"column:FKSJ"` //放款时间
	FKJE  float64   `gorm:"column:FKJE"` //放款金额
	RZSJ  float64   `gorm:"column:RZSJ"` //入账收入
	YXGH  string    `gorm:"column:YXGH"` //协同营销工号
	EMID  int       `gorm:"column:EMID"`
	DRRQ  time.Time `gorm:"column:DRRQ"`  //业绩统计日期
	CZRID int       `gorm:"column:CZRID"` //操作人ID
	CZR   string    `gorm:"column:CZR"`   //操作人
	CZRQ  time.Time `gorm:"column:CZRQ"`  //操作日期
}

//TableName
func (ShXykfqzsdr) TableName() string {
	return "SH_INDI_XYKFQZS"
}

// BeforeCreate
func (u *ShXykfqzsdr) BeforeCreate(tx *gorm.DB) (err error) {
	var emid *int
	tx.Raw(`select "ID" from "T_SysUser" where "SysUserID" = ?`, u.YXGH).Row().Scan(&emid)
	if emid == nil {
		err = fmt.Errorf("员工号%s在系统中不存在！", u.YXGH)
		return
	}
	u.EMID = *emid
	u.CZRQ = time.Now()
	return
}

//ShXykfqzsdrEF 返回结构体
func ShXykfqzsdrEF() base.EntityFunc {
	return func() interface{} {
		entity := ShXykfqzsdr{}
		return &entity
	}
}

//ShXykfqzsdrESF 返回结构体数组
func ShXykfqzsdrESF() base.EntitiesFunc {
	return func() interface{} {
		var entities []ShXykfqzsdr
		return &entities
	}
}

func init() {
	base.DaoPoolObj.Put("ShXykfqzsdr", base.NewDefaultDao(ShXykfqzsdrEF(), ShXykfqzsdrESF(), nil, "my"))
}
